package com.lss233.recipeguide;

import com.lss233.recipeguide.executor.RecipeExecutor;
import com.lss233.recipeguide.listener.GuiAddListener;
import com.lss233.recipeguide.listener.GuiMenuListener;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * @author Lss233
 */
public class RecipeGuide extends JavaPlugin {
    private static RecipeGuide instance;

    public static RecipeGuide getInstance() {
        return instance;
    }

    public void onEnable(){
        instance = this;
        if(!getDataFolder().exists()){
            getDataFolder().mkdir();
        }
        getServer().getPluginManager().registerEvents(new GuiAddListener(this),this);
        getServer().getPluginManager().registerEvents(new GuiMenuListener(),this);
        getCommand("recipe").setExecutor(new RecipeExecutor());
        Storage.reload();
    }

    public static void sendThrowable(Entity feedback, Exception e) {
        feedback.sendMessage(ChatColor.RED+"DEBUG - Exception:"+e.getLocalizedMessage());
        for (StackTraceElement stackTraceElement : e.getStackTrace()) {
            feedback.sendMessage(ChatColor.BLUE +stackTraceElement.getClassName()+ChatColor.GRAY+"["+ChatColor.GOLD+stackTraceElement.getMethodName()+ChatColor.GRAY+":"+ChatColor.RED+stackTraceElement.getLineNumber()+ChatColor.GRAY+"]");
        }

    }
}
